﻿
#region Using Directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TeamArchitect.PowerTools.Features;

#endregion

namespace FeatureBuilder.ContribLib.Commands
{
    /// <summary>
    /// Feature Extension Command that adds a Project Dependency to a Project.
    /// </summary>
    [DisplayName("Add Project Dependency")]
    [Description("Adds a Project dependency to a Project")]
    [Category("IDE")]
    public class AddProjectDependency : FeatureCommand
    {
        public Project Project { get; set; }
        public Project DependencyProject { get; set; }

        /// <summary>
        /// Gets the ServiceProvider that we will use to get a reference to DTE.
        /// </summary>
        [Import(typeof(SVsServiceProvider))]
        public IServiceProvider ServiceProvider { get; private set; }

        #region Overrides

        public override void Execute()
        {
            try
            {
                DTE dte = this.ServiceProvider.GetService(typeof(DTE)) as DTE;
                dte.Solution.SolutionBuild.BuildDependencies.Item(Project).AddProject(DependencyProject.UniqueName);
            }
            catch { }
        }

        #endregion
    }
}
